﻿Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace DotNetNuke.Modules.ActiveForums.Controls
    <DefaultProperty("Text"), ToolboxData("<{0}:ScriptLoader runat=server></{0}:ScriptLoader>")> _
    Public Class ScriptLoader
        Inherits Control

#Region "Declarations"

        Private _TextSuggest As Boolean = False
        Private _ActiveGrid As Boolean = False
        Private _Callback As Boolean = False
        Private _DatePicker As Boolean = False
        Private _RequiredFieldValidator As Boolean = False
        Private _NumberSpinner As Boolean = False


#End Region

#Region "Properties"

        Public Property TextSuggest() As Boolean
            Get
                Return _TextSuggest
            End Get
            Set(ByVal value As Boolean)
                _TextSuggest = value
            End Set
        End Property
        Public Property ActiveGrid() As Boolean
            Get
                Return _ActiveGrid
            End Get
            Set(ByVal value As Boolean)
                _ActiveGrid = value
            End Set
        End Property
        Public Property Callback() As Boolean
            Get
                Return _Callback
            End Get
            Set(ByVal value As Boolean)
                _Callback = value
            End Set
        End Property
        Public Property DatePicker() As Boolean
            Get
                Return _DatePicker
            End Get
            Set(ByVal value As Boolean)
                _DatePicker = value
            End Set
        End Property
        Public Property RequiredFieldValidator() As Boolean
            Get
                Return _RequiredFieldValidator
            End Get
            Set(ByVal value As Boolean)
                _RequiredFieldValidator = value
            End Set
        End Property

        Public Property NumberSpinner() As Boolean
            Get
                Return _NumberSpinner
            End Get
            Set(ByVal value As Boolean)
                _NumberSpinner = value
            End Set
        End Property

#End Region

#Region "Subs/Functions"

        Private Sub ScriptLoader_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If TextSuggest = True And Not Page.ClientScript.IsClientScriptIncludeRegistered("AMTextSuggest") Then
                '  Page.ClientScript.RegisterClientScriptInclude("AMTextSuggest", Page.ClientScript.GetWebResourceUrl(Me.GetType, "TextSuggest.js"))
            End If
            If ActiveGrid = True And Not Page.ClientScript.IsClientScriptIncludeRegistered("AMActiveGrid") Then
                Page.ClientScript.RegisterClientScriptInclude("AMActiveGrid", Page.ClientScript.GetWebResourceUrl(Me.GetType, "ActiveGrid.js"))
            End If
            If Callback = True And Not Page.ClientScript.IsClientScriptIncludeRegistered("AMCallback") Then
                Page.ClientScript.RegisterClientScriptInclude("AMCallback", Page.ClientScript.GetWebResourceUrl(Me.GetType, "cb.js"))
            End If
            If DatePicker = True And Not Page.ClientScript.IsClientScriptIncludeRegistered("AMDatePicker") Then
                Page.ClientScript.RegisterClientScriptInclude("AMDatePicker", Page.ClientScript.GetWebResourceUrl(Me.GetType, "DatePicker.js"))
            End If
            If RequiredFieldValidator = True And Not Page.ClientScript.IsClientScriptIncludeRegistered("AMValidation") Then
                Page.ClientScript.RegisterClientScriptInclude("AMValidation", Page.ClientScript.GetWebResourceUrl(Me.GetType, "Validation.js"))
            End If
            If Not Page.ClientScript.IsClientScriptIncludeRegistered("AMNumberSpinner") Then
                Page.ClientScript.RegisterClientScriptInclude("AMNumberSpinner", Page.ClientScript.GetWebResourceUrl(Me.GetType, "NumberSpinner.js"))
            End If
            If Not Page.ClientScript.IsClientScriptIncludeRegistered("AMMenu") Then
                Page.ClientScript.RegisterClientScriptInclude("AMMenu", Page.ClientScript.GetWebResourceUrl(Me.GetType, "MenuButton.js"))
            End If
        End Sub

#End Region

    End Class
End Namespace
